const app = getApp();
const _requsetCYZ = require('../../../utils/requestData');
const _functionCYZ = require('../../../utils/common');
Page({
    data: {
        this_page_size: 1,
        this_page_num: 10,
        is_loadmore: true,
        this_cms_xianlu_top: null,
        this_index_data: null,
        this_s_title: '',
        this_config_op: null,
        this_login_user_id: 0
    },
    onLoad: function (op) {
        var that = this;
        that.setData({ this_config_op: op });
        that.getIndexData();
    },
    getIndexData: function () {
        var that = this;
        _functionCYZ.CYZ_loading();
        var requestData = {};
        requestData.keywords = that.data.this_s_title;
        requestData.cate_id = 7;
        requestData.pagesize = that.data.this_page_size;
        requestData.pagenum = that.data.this_page_num;
        _requsetCYZ.cyz_requestGet('/WuliuCmsApiIndex/getXianluList', requestData, function (cyz_data) {
            wx.hideToast();
            if (cyz_data.info.this_data_list == null) {
                that.setData({ is_loadmore: false });
            } else {
                if (cyz_data.info.this_data_list.length < that.data.this_page_num) {
                    that.setData({ is_loadmore: false });
                }
            }
            that.setData({ this_index_data: cyz_data.info.this_data_list, this_cms_xianlu_top: cyz_data.info.this_cms_xianlu_top });
        });
    },
    onReachBottom: function (e) {
        var that = this;
        if (that.data.is_loadmore == false) {
            return false;
        }
        _functionCYZ.CYZ_loading();
        var requestData = {};
        requestData.keywords = that.data.this_s_title;
        requestData.cate_id = 7;
        requestData.pagesize = that.data.this_page_size + 1;
        requestData.pagenum = that.data.this_page_num;
        _requsetCYZ.cyz_requestGet('/WuliuCmsApiIndex/getXianluList', requestData, function (xyz_data) {
            wx.hideToast();
            if (xyz_data.info.this_data_list == null) {
                that.setData({ is_loadmore: false });
            } else {
                if (xyz_data.info.this_data_list.length < that.data.this_page_num) {
                    that.setData({ is_loadmore: false });
                }
                var this_new_info_data = that.data.this_index_data;
                this_new_info_data = this_new_info_data.concat(xyz_data.info.this_data_list);
                that.setData({ this_index_data: this_new_info_data, this_page_size: requestData.pagesize });
            }
        });
    },
    //搜索
    changeSearchStatus: function () {
        this.setData({ search_open_status: this.data.search_open_status ? false : true });
    },
    //搜索
    searchTitle: function (e) {
        this.setData({ this_s_title: e.detail.value });
    },
    onSearch: function (e) {
        var that = this;
        that.setData({ is_load_more: true, tabIndex: 0, this_page_size: 1 });
        that.getIndexData();//加载数据
    },
    // 关闭搜索
    closeSearch: function (e) {
        var that = this;
        if (that.data.this_s_title != '') {
            that.setData({ tabIndex: 0, is_loadmore: true, this_s_title: '', this_page_size: 1 });
            that.onShow();//加载数据
        }
    },
    onPullDownRefresh: function () {
        var that = this;
        that.setData({ this_page_size: 1, is_loadmore: true });
        that.getIndexData();
        setTimeout(() => {
            wx.stopPullDownRefresh()
        }, 1000);
    },
    /**
     * 跳转页面
     */
    onAppNavigateTap: function (e) {
        const dataset = e.detail.target ? e.detail.target.dataset : e.currentTarget.dataset;
        const url = dataset.url, appurl = dataset.appurl, atype = dataset.atype || 1, appId = dataset.appid;
        if (atype == 1) {
            if (url == '') return false;
            wx.navigateTo({
                url: url, fail: () => {
                    wx.switchTab({
                        url: url,
                    });
                }
            });
        } else if (atype == 2) {
            wx.navigateToMiniProgram({ appId: appId, path: appurl });
        }
    },
    onShareAppMessage: function () {
        var that = this;
        var shareTitle = '省外线路';
        var sharePath = 'pages/wuliucms/abroad_one/abroad';
        return {
            title: shareTitle,
            desc: '',
            path: sharePath
        }
    },
})